#coding=utf-8
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound

from apps.wuliu.models.wuliu import *

app = Blueprint('app_wuliu', __name__, template_folder='../templates', static_folder='static')

@app.route('/')
def index():
    try:
        return render_template('wuliu/index.html', alpha_list=City.find_top_cities())
    except TemplateNotFound:
        abort(404)

@app.route('/huoyuan')
def huoyuan():
    try:
        return render_template('wuliu/huoyuan.html')
    except TemplateNotFound:
        abort(404)

@app.route('/huangye')
def huangye():
    try:
        return render_template('wuliu/huangye.html')
    except TemplateNotFound:
        abort(404)

@app.route('/zixun')
def zixun():
    try:
        return render_template('wuliu/zixun.html')
    except TemplateNotFound:
        abort(404)

@app.route('/shequ')
def shequ():
    try:
        return render_template('wuliu/shequ.html')
    except TemplateNotFound:
        abort(404)

'''
@app_wuliu.route('/wuliu/:static#js|css|img#/:path#.+#')
def server_static(static, path):
    return static_file('%s/%s' % (static, path), root='app_wulius/wuliu/static')

@app_wuliu.get('/')
@view('index')
def index():
    return {'alpha_list': City.find_branch('alpha')}

@app_wuliu.get('/huoyuan')
@view('huoyuan')
def huoyuan():
    return {'top_cities': City.find_top_cities(), 'trans_type_list': TransType.find_branch()}

@app_wuliu.get('/huangye')
@view('huangye')
def huangye():
    cities = City.find_level(2)
    return {'top_cities': City.find_top_cities(), 'trans_type_list': TransType.find_branch()}

@app_wuliu.get('/zixun')
@view('zixun')
def zixun():
    return {}

@app_wuliu.get('/shequ')
@view('shequ')
def shequ():
    return {}

@app_wuliu.get('/xhr_get_sub_cities')
def get_sub_cities():
    kw = dict(request.GET)
    return {'sub_cities': to_json(City.find_sub_cities(kw['parent_id']), 'id', 'name')}
'''